<?php
namespace Admin\Controller;
use Think\Controller;
use Org\Util\String;
use Think\Page;
	class AdminController extends CommonController{
		
		
		public function del(){
			$m=M('Admin');
			$count = $m ->count();
			if($count<=1){
				$this->error('唯一管理员不能删除');
			}
			
			$id=$_GET['id'];
			$num=$m->delete($id);
			if($num>0){
				$this->success('删除用户成功');
			}else{
				$this->error('数据删除失败');
			}
		}
		
		
		
		public function updatepwd(){
			$admin=D('Admin');
			$count=$admin->update_pwd();
			if($count>0){
				$this->success('数据修改成功','index');
			}else{
				$this->error('数据修改失败');
			}
		}
		
		
		public function create(){
			$m=D('Admin');
			$salt = String::randString(10);
			$data['salt'] = $salt;
			$data['password'] = md5($_POST['password'].$salt);
			$data['created_at'] = date("Y-m-d H:i:s");
			$data['username'] = $_POST['username'];
			$data['email'] = $_POST['email'];
			if(!$m->create($data)){
				$this->error($m->getError());
			}
			$idNum=$m->add();
			if($idNum>0){
				$this->success('添加用户成功','index');
			}else{
				$this->error('数据添加失败');
			}
		}
	}
?>
